﻿using SuperX.Common;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Text;

namespace SuperX.Common.Code
{
    public interface ICode : IBasicObject
    {
        dynamic Execute(string expression);

        TR Execute<TR>(string expression);

        /// <summary>
        /// 设置C# dll程序集查找路径
        /// </summary>
        /// <param name="dllPaths">C# dll程序集查找路径</param>
        void SetSearchPaths(List<string> dllPaths);

        /// <summary>
        /// 追加C# dll程序集查找路径
        /// </summary>
        /// <param name="dllPaths">C# dll程序集查找路径</param>
        void AppentSearchPaths(List<string> dllPaths);

        void SetVariable(string key, object value);
    }

    public interface ICode<TSE> : ICode
    {
        TSE InitEngine(string engineName);

        TSE InitEngine(string engineName, IDictionary<string, object> mapObjects);
    }

    public interface ICodeScope<TSE, TSC> : ICode<TSE>
    {
        ConcurrentDictionary<string, TSC> Scopes { get; set; }

        dynamic Execute(string expression, TSC scope);

        TR Execute<TR>(string expression, TSC scope);

        TSC CreateScope();

        TSC CreateScope(IDictionary<string, object> dictionary);

        TSC GetScope(string path);
    }

    public interface ICodeSource<TSS, TSC>
    {
        TSS CreateScriptSourceFromFile(string path, Encoding encoding, TSC kind);

        TSS CreateScriptSourceFromFile(string path, Encoding encoding);

        TSS CreateScriptSourceFromFile(string path);

        TSS CreateScriptSourceFromString(string code, string path, TSC kind);

        TSS CreateScriptSourceFromString(string expression, string path);

        TSS CreateScriptSourceFromString(string code, TSC kind);

        TSS CreateScriptSourceFromString(string expression);
    }
}